package com.codi.bus.core.dao.impl;

import com.codi.base.dao.BaseDAOImpl;
import com.codi.bus.core.dao.FundCombinationMappingDao;
import com.codi.bus.core.domain.FundCombinationMapping;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository("fundCombinationMappingDao")
public class FundCombinationMappingDaoImpl extends BaseDAOImpl<FundCombinationMapping> implements FundCombinationMappingDao{

    @Override
    public List<FundCombinationMapping> selectAll() {
        List<FundCombinationMapping> mappings = this.findList(generateStatement("selectAll"));
        return mappings;
    }


    @Override
    public List<FundCombinationMapping> query(String combinationCode) {
        Map<String, Object> map = new HashMap<>();
        map.put("fundCombinationCode", combinationCode);
        List<FundCombinationMapping> mappings = this.findList(generateStatement("queryByCombinationCode"), map);

        return mappings;
    }

    @Override
    public FundCombinationMapping query(String combinationCode, String fundCode) {
        Map<String, Object> map = new HashMap<>();
        map.put("fundCombinationCode", combinationCode);
        map.put("fundCode", fundCode);

        return this.getObject(generateStatement("queryByCombinationCodeAndFundCode"), map);
    }

    @Override
    public int add(FundCombinationMapping mapping) {
        mapping.setFundCurrencyAccumIncome(0F);
        return this.insert(generateStatement("insertSelective"), mapping);
    }

    @Override
    @Transactional(readOnly = false)
    public int updateMapping(FundCombinationMapping mapping) {
        return this.update(generateStatement("updateByPrimaryKeySelective"), mapping);
    }

    @Override
    public int delete(Long mappingId) {
        return this.delete(generateStatement("deleteByPrimaryKey"), mappingId);
    }

    @Override
    public int deleteByCombinationCode(String combinationCode) {
        return this.delete(generateStatement("deleteByCombinationCode"), combinationCode);
    }

    @Override
    public FundCombinationMapping queryByPrimaryKey(Long mappingId) {
        return this.getObject(generateStatement("selectByPrimaryKey"), mappingId);
    }


}
